package com.example.work4.adapter;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import java.util.Objects;

public class RecyclerLine extends RecyclerView.ItemDecoration {

    private int space;//空白间隔

    public RecyclerLine(int space) {
        this.space = space;
    }

    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int childAdapterPosition = parent.getChildAdapterPosition(view);
        if (childAdapterPosition == Objects.requireNonNull(parent.getAdapter()).getItemCount() - 1) {
            outRect.set(0, space, 0, 0);
        }
        if (childAdapterPosition == 0) {
            outRect.set(0, 0, 0, space);
        }
        outRect.bottom = space;//下方空白间隔
        outRect.top = space;//上方空白间隔
    }
}
